package com.bianyuanren.v4.controller.version;

import com.bianyuanren.v4.service.version.IPpVersionService;
import com.bianyuanren.v4.pojo.version.PpVersion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bianyuanren.common.core.controller.BaseController;
import com.bianyuanren.common.core.domain.AjaxResult;

/**
 * 边缘人版本号控制Controller
 * 
 * @author bianyuanren
 * @date 2020-03-16
 */
@Controller
@RequestMapping("/api/version")
public class PpVersionController extends BaseController
{
    @Autowired
    private IPpVersionService ppVersionService;

    /**
     * 版本控制
     * versionName 版本名字
     *  platform 平台 0--安卓  1--ios
     */
    @PostMapping("/newest")
    @ResponseBody
    public AjaxResult newest(String versionName,int platform) {
        //返回0强制更新 1最新的或不用强制更新
        PpVersion ppVersion = ppVersionService.selectPpVersion(versionName,platform);
        if (ppVersion!=null && ppVersion.getForcedUpdating()==0){
            System.out.println("++++++++++++++++++++++"+ppVersion.getVersionUrl());
            return new AjaxResult(509,ppVersion.getVersionUrl(),ppVersion.getForcedUpdating());
        }
        return  AjaxResult.success(0);
    }
}
